******************************************************
* 2. INTERNATIONAL COVERAGE + DESCRIPTIVE STATISTICS *
******************************************************

************************************************
* CONTENT:	(1) Checking coverage WVS          *
*			(2) Descriptive statisitics of QOG *
************************************************

* (1) Checking coverage WVS
***************************

* Loading QOG dataset

use WPO_QOG_WVS.dta, clear

* Creating wave variables (WVS wave ID, and number of years in each wave)

gen wave=.
replace wave=1 if year>=1981 & year<=1984
replace wave=2 if year>=1989 & year<=1993
replace wave=3 if year>=1994 & year<=1998
replace wave=4 if year>=1999 & year<=2004
replace wave=5 if year>=2005 & year<=2009
replace wave=6 if year>=2010 & year<=2014
replace wave=7 if year>=2017 & year<=2021

gen nbr_years_wave=.
replace nbr_years_wave=4 if wave==1
replace nbr_years_wave=5 if wave==2
replace nbr_years_wave=5 if wave==3
replace nbr_years_wave=6 if wave==4
replace nbr_years_wave=5 if wave==5
replace nbr_years_wave=5 if wave==6
replace nbr_years_wave=4 if wave==7

* Creating a variable with the total number of countries in each wave (according to UN: http://www.un.org/en/sections/member-states/growth-united-nations-membership-1945-present/index.html)


gen nbr_countries=.
replace nbr_countries=157+157+158+159 if wave==1 // 1981-1984
replace nbr_countries=159+159+166+179+184 if wave==2 // 1989-1993
replace nbr_countries=185+185+185+185+185 if wave==3 // 1994-1998
replace nbr_countries=188+189+189+191+191+191 if wave==4 // 1999-2004
replace nbr_countries=191+192+192+192+192 if wave==5 // 2005-2009
replace nbr_countries=192+193+193+193+193 if wave==6 // 2010-2014
replace nbr_countries=193+193+193+193 if wave==7 // 2017-2020

replace nbr_countries=nbr_countries/nbr_years_wave // taking the average over the years in each wave

* Identifying countries covered by dependnet variable

gen E114_constant=0
replace E114_constant=1 if E114_mean_wvs!=. & E114_mean_wvs>0 & UN==1 // Creating a variable that takes the value of 1 when the dependent variable is available and 0 otherwise

gen E117_constant=0
replace E117_constant=1 if E117_mean_wvs!=. & E117_mean_wvs>0 & UN==1

gen D059_constant=0
replace D059_constant=1 if D059_mean_wvs!=. & D059_mean_wvs>0 & UN==1

* Claculating proportions by wave

bysort wave: egen nbr_countries_E114=total(E114_constant)
gen prop_E114=nbr_countries_E114/nbr_countries

bysort wave: egen nbr_countries_E117=total(E117_constant)
gen prop_E117=nbr_countries_E117/nbr_countries

bysort wave: egen nbr_countries_D059=total(D059_constant)
gen prop_D059=nbr_countries_D059/nbr_countries

* Results
bysort wave: gen group_id_wave=1 if _n==1 // Creating ID wave variable

tab prop_E114 wave if group_id_wave==1
tab prop_E117 wave if group_id_wave==1
tab prop_D059 wave if group_id_wave==1

* Proportion of population of the world covered
* World population by wave (from wordometer http://www.worldometers.info/world-population/world-population-by-year/)

* Calculating average world population in each wave

gen pop_wave=.
replace pop_wave=4537845777+4618776168+4701530843+4786483862 if wave==1 // 1981-1984
replace pop_wave=5240735117+5330943460+5418758803+5504401149+5588094837	if wave==2 // 1989-1993
replace pop_wave=5670319703+5751474416+5831565020+5910566295+5988846103	if wave==3 // 1994-1998
replace pop_wave=6066867391+6145006989+6223412158+6302149639+6381408987+6461370865 if wave==4 // 1999-2004
replace pop_wave=6542159383+6623847913+6706418593+6789771253+6873741054	if wave==5 // 2005-2009
replace pop_wave=6958169159+7043008586+7128176935+7213426452+7298453033 if wave==6 // 2010-2014
replace pop_wave=7547858925+7631091040+7713468100+7794798739 if wave==7 // 2017-2020

replace pop_wave=pop_wave/nbr_years_wave

* Identifying countries covered by the outcome variables

replace E114_constant=0
replace E114_constant=1 if E114_mean_wvs!=. & E114_mean_wvs>0

replace E117_constant=0
replace E117_constant=1 if E117_mean_wvs!=. & E117_mean_wvs>0

replace D059_constant=0
replace D059_constant=1 if D059_mean_wvs!=. & D059_mean_wvs>0

bysort wave: egen pop_E114=total(wdi_pop) if E114_constant==1
gen prop_E114_pop=pop_E114/pop_wave

bysort wave: egen pop_E117=total(wdi_pop) if E117_constant==1
gen prop_E117_pop=pop_E117/pop_wave

bysort wave: egen pop_D059=total(wdi_pop) if D059_constant==1
gen prop_D059_pop=pop_D059/pop_wave

* Results

tab prop_E114_pop wave
tab prop_E117_pop wave
tab prop_D059_pop wave

* (2) Descriptive stats of QOG
******************************

sum wdi_pop wdi_popf wdi_pop14 wdi_pop65 vdem_libdem vdem_corr wdi_gdpcappppcur wdi_tele wdi_araland lp_lat_abst wdi_popurb lp_catho80 lp_muslim80 lp_protmg80 if wave>2 & year<=2020
